package com.atguigu.yygh.user.controller;


import com.atguigu.yygh.common.result.Result;
import com.atguigu.yygh.common.utils.AuthContextHolder;
import com.atguigu.yygh.model.user.Patient;
import com.atguigu.yygh.user.service.IPatientService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * <p>
 * 就诊人表 前端控制器
 * </p>
 *
 * @author Fxq
 * @since 2022-04-06
 */
@RestController
@RequestMapping("/api/user/patient")
@Api(value = "PatientController",tags = "就诊人管理")
public class PatientController {

    @Resource
    private IPatientService patientService;

    @GetMapping("auth/findAll")
    @ApiOperation(value = "获取就诊人列表")
    public Result findAll(HttpServletRequest request) {
        //获取当前登录用户id
        Long userId = AuthContextHolder.getUserId(request);
        List<Patient> list = patientService.findAllUserId(userId);
        return new Result(list);
    }

    @PostMapping("auth/save")
    @ApiOperation(value = "添加就诊人")
    public Result savePatient(@RequestBody Patient patient, HttpServletRequest request) {
        //获取当前登录用户id
        Long userId = AuthContextHolder.getUserId(request);
        patient.setUserId(userId);
        patientService.save(patient);
        return new Result("添加成功");
    }

    @GetMapping("auth/get/{id}")
    @ApiOperation(value = "根据id获取就诊人信息")
    public Result getPatient(@PathVariable Long id) {
        Patient patient = patientService.getPatientId(id);
        return new Result(patient);
    }

    @PostMapping("auth/update")
    @ApiOperation(value = "修改就诊人信息")
    public Result updatePatient(@RequestBody Patient patient) {
        patientService.updateById(patient);
        return new Result("修改就诊人信息成功");
    }

    @DeleteMapping("auth/remove/{id}")
    @ApiOperation(value = "删除就诊人信息")
    public Result removePatient(@PathVariable Long id) {
        patientService.removeById(id);
        return new Result("删除就诊人信息成功");
    }

    @GetMapping("inner/get/{id}")
    @ApiOperation(value = "根据id获取就诊人信息")
    public Patient getPatientById(@PathVariable Long id) {
        Patient patient = patientService.getPatientId(id);
        return patient;
    }

}

